﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Webcar.BLL;
using ToolsLayer;
using BusinessEntity;
namespace Webcar.Controls
{
    public partial class CarCostQuery : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
                return;

            GridViewStyler gvs = new GridViewStyler(this.GridView1);
            gvs.SetGridHover = false;
            gvs.SetStyle();
        }

        public void BindData(string sdt, string edt)
        {
            string sql = "SELECT a.[dept_Code],b.dept_name " +
              ",sum([zs_fee]) zs_fee" +
              ",sum([cl_fee]) [cl_fee] " +
              ",sum([lq_fee]) [lq_fee]" +
              ",sum([xc_fee]) [xc_fee]" +
              ",sum([tc_fee]) [tc_fee]" +
              ",sum([ns_fee]) [ns_fee]" +
              ",sum([lq_year]) [lq_year]" +
              ",sum([lq_month]) [lq_month]" +
              ",sum([road_fee]) [road_fee]" +
              ",sum([oil_fee]) [oil_fee]" +
              ",sum([other_fee]) [other_fee]" +
              ",sum([oil_nums]) [oil_nums]" +
              ",sum([oil_price]) [oil_price]" +
              ",sum([sum_fee])  [sum_fee]" +
              " FROM [webcar].[dbo].[CarCost] a,dept b where a.dept_code=b.dept_code" +
              " and a.month between '{0}' and '{1}'" +
              " group by b.dept_name,a.[dept_Code]" +
              " union all" +
              " SELECT 'ALL','合计：' " +
              ",sum([zs_fee]) zs_fee" +
              ",sum([cl_fee]) [cl_fee] " +
              ",sum([lq_fee]) [lq_fee]" +
              ",sum([xc_fee]) [xc_fee]" +
              ",sum([tc_fee]) [tc_fee]" +
              ",sum([ns_fee]) [ns_fee]" +
              ",sum([lq_year]) [lq_year]" +
              ",sum([lq_month]) [lq_month]" +
              ",sum([road_fee]) [road_fee]" +
              ",sum([oil_fee]) [oil_fee]" +
              ",sum([other_fee]) [other_fee]" +
              ",sum([oil_nums]) [oil_nums]" +
              ",sum([oil_price]) [oil_price]" +
              ",sum([sum_fee])  [sum_fee]" +
              " FROM [webcar].[dbo].[CarCost] a,dept b where a.dept_code=b.dept_code and isnull(b.del_flag,'F')='F'" +
              " and a.month between '{0}' and '{1}'";
              

            sql = string.Format(sql, sdt, edt);
            this.GridView1.DataSource = DB.ExecuteDataset(sql);
            this.GridView1.DataBind();
        }
    }
}